/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
	"fmt"

	"github.com/spf13/cobra"
)

// testFlagCmd represents the testFlag command
var testFlagCmd = &cobra.Command{
	Use:   "testFlag",
	Short: "testFlag --persist=? --local=?",
	Run: func(cmd *cobra.Command, args []string) {
		// 打印 flag
		fmt.Println("testFlag called : localFlag is ", localFlag)
		fmt.Println("testFlag called : persistFlag is ", persistentFlag)
	},
}
// 定义 testFlag 的子命令
var testChildCmd = &cobra.Command{
	Use:   "testChild",
	Short: "testChild --persist=?",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("testChild called : persistFlag is ", persistentFlag)
	},
}

// 定义参数
var (
	localFlag string
	persistentFlag bool
)

func init() {
	rootCmd.AddCommand(testFlagCmd)
	// 添加 testChild
	testFlagCmd.AddCommand(testChildCmd)

	// Here you will define your flags and configuration settings.
	// 父命令接收持久标志
	// 参数依次是 变量地址，参数名，参数简写，默认值，参数说明
	testFlagCmd.PersistentFlags().BoolVarP(&persistentFlag,"persist","p",false,"全局持久标志")
	// 父命令接收本地标志
	testFlagCmd.Flags().StringVarP(&localFlag,"local","l","","本地标志")

}
